package cn.stronglink.assetmanage.business.check.view.wait;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.adapter.CheckOrderAdapter;
import cn.stronglink.assetmanage.business.check.view.CheckFragment;
import cn.stronglink.assetmanage.business.check.view.detail.WaitCheckDetailFragment;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 操作待入库界面
 * Created by chencongcong on 2018/6/12.
 */

public class WaitAssetView {
    private Fragment fragment;
    //表单号
    @BindView(R.id.tv_checkwait_order_name)
    TextView tv_checkwait_order_name;
    //表单创建日期
    @BindView(R.id.tv_checkwait_operation_date)
    TextView tv_checkwait_operation_date;
    //资源列表adapter
    private CheckOrderAdapter orderAdapter;
    //执行日期
    @BindView(R.id.tv_checkwait_operation_date_1)
    TextView tv_checkwait_operation_date_1;

    public WaitAssetView(Fragment fragment, View view, CheckOrderAdapter orderAdapter) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        this.orderAdapter = orderAdapter;
    }

    /**
     * 设置选中表单的资产列表数据
     *
     * @param orderData
     */
    public void setOrderData(List<Asset> orderData) {
        if (orderAdapter != null) {
            orderAdapter.notifyDatasChanged(orderData);
        }
    }

    /**
     * 显示未入库资源列表表头
     */
    public void showAssetTitle(Check check) {
        if (check != null) {
            tv_checkwait_order_name.setText(check.getId_());
            tv_checkwait_operation_date.setText(check.getCreateTime());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            //执行日期为当前日期
            tv_checkwait_operation_date_1.setText(sdf.format(new Date()));
        }
    }

    public void showWaitOrderDetail(Asset asset) {
        //跳转到详情页面
        Fragment detailFragment = new WaitCheckDetailFragment();
        FragmentManager fragmentManager = fragment.getActivity().getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.frame_business, detailFragment);
        transaction.commit();
        Bundle bundle = new Bundle();
        bundle.putString(Constants.CHECK_IN_DETAIL_NO, asset.getId_());
        detailFragment.setArguments(bundle);
    }

    /**
     * 返回单子列表页面，
     *
     * @param fragmentIndex 本fragment在tablayout中的位置
     */
    public void backCheckFragment(int fragmentIndex) {
        Fragment checkFragment = new CheckFragment();
        FragmentManager fragmentManager = checkFragment.getActivity().getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.frame_business, checkFragment);
        transaction.commit();
        Bundle bundle = new Bundle();
        bundle.putInt(Constants.CHECK_IN_DETAIL_NO, fragmentIndex);
        checkFragment.setArguments(bundle);
    }
}
